<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function add(){
				
				var tr = document.createElement("tr");
				document.getElementById("stuTable").appendChild(tr);
				var td = document.createElement("td");
				var sname = document.createElement("text");
				sname.innerText = "学生姓名："
				var input = document.createElement("input");
				input.type = "text";
				
				td.appendChild(sname);
				td.appendChild(input);
				tr.appendChild(td);
				
				
				document.getElementById("stuTable").appendChild(tr);
				var td = document.createElement("td");
				var schengj = document.createElement("text");
				schengj.innerText = "学生成绩："
				var input = document.createElement("input");
				input.type = "text";
				td.appendChild(schengj);
				td.appendChild(input);
				tr.appendChild(td);
				
				
			}
			var i = 0;
			function addstu(){
				add();
				i++;
			}
			function jisuan(){
				document.getElementById("num").value = i;
			}
			
			function number(){
				var o = document.getElementById("stuTable").children;
				var sum = 0;
				for(n = 0 ; n < o.length ; n++){
					sum = sum + Number(o[n].children[1].children[1].value);
				}
				
				var fen = sum / i;
				
				document.getElementById("avg").value = fen;
			}
			function number1(){
				jisuan();
				number();
			}
		</script>
	</head>
	<body>
		<form action="" method="">
			<table id="stuTable">
			学生平均分：<input type="text" id="avg">
			学生人数：<input type="text" id="num" >
			<hr >
			</table>
			<hr >
			<input type="button" value="计算" onclick="number1()"/>
			<input type="button" value="增加" onclick="addstu()"/>
		</form>
	</body>
</html>
